<template>
	<div>
		<ul>
			<li v-for="(v, i) in address" :key="i">

				<input type="radio" :value="v.id" v-model="id">

				<div class="item">
					<p>{{ v.nickname }}-{{ v.tel }}</p>
					<p>{{ v.address }}</p>
				</div>
			</li>
		</ul>
		<button @click="handleSave">设为默认地址</button>
		<button @click="$router.push({ name: 'addAddress' })">新增</button>
		<pre>{{ address }}</pre>
	</div>
</template>

<script>
export default {
	data() {
		return {
			id: ''
		}
	},
	methods: {
		handleSave() {
			this.$store.commit('SET_DEFAULT_ADDRESS', { id: this.id })
			this.$router.push({ path: '/' })
		}
	},
	computed: {
		address() {
			return this.$store.state.address
		}
	},
	created() {
		this.address.length === 0 && this.$store.dispatch('GET_ADDRESS')
	}
}
</script>

<style scoped>
ul li {
	display: flex;
	padding: 10px;
	border-bottom: 1px solid #ccc;
	margin: 10px 0;
}
</style>